﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wintellect.PowerCollections;

namespace zad1
{
    class PriorityQueue<T> : IEnumerable<T>
        where T : IComparable
    {
        private OrderedBag<T> queue;

        public PriorityQueue()
        {
            queue = new OrderedBag<T>();
        }

        public PriorityQueue(IComparer<T> comparer)
        {
            queue = new OrderedBag<T>(comparer);
        }

        public void Add(T element)
        {
            queue.Add(element);
        }

        public void Remove(T element)
        {
            queue.Remove(element);
        }

        public IEnumerator<T> GetEnumerator()
        {
            foreach (T item in queue)
            {
                yield return item;
            }
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }

        public int Count
        {
            get
            {
                return queue.Count;
            }
        }

        public T this[int index]
        {
            get
            {
                if (index >= 0 && index < queue.Count)
                {
                    return queue[index];
                }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
    }
}
